package com.open.party.cloud.view.home.jiCengDangJian.partyService

import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import cn.android.x.parent.AppTitleBaseActivity
import com.open.party.cloud.R
import com.open.party.cloud.view.home.jiCengDangJian.fragment.ZyzSignInListFragment
import com.open.party.cloud.view.home.jiCengDangJian.fragment.ZyzSignInMainFragment
import kotlinx.android.synthetic.main.activity_zyz_kaoqing.*

/**
 * 考勤
 */
class ZyzKaoQingMainActivity : AppTitleBaseActivity(), View.OnClickListener {

    var activityId = ""

    override fun getLayoutResId(): Int = R.layout.activity_zyz_kaoqing

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setViewTitle("活动签到")

        activityId = intent.getStringExtra("activityId") as String

        initView()
        initListener()
    }

    private fun initView() {
        val fragments = ArrayList<Fragment>()
        fragments.add(ZyzSignInMainFragment())
        fragments.add(ZyzSignInListFragment())

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = fragments.size - 1
        viewPager.adapter = fragmentPagerAdapter
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
                when (position) {
                    0 -> {
                        tab01Txt.setTextColor(ContextCompat.getColor(this@ZyzKaoQingMainActivity, R.color.page_title))
                        tab01Line.setBackgroundResource(R.color.theme_color)
                        tab02Txt.setTextColor(ContextCompat.getColor(this@ZyzKaoQingMainActivity, R.color.page_sub))
                        tab02Line.setBackgroundResource(R.color.transparent)
                    }
                    1 -> {
                        tab01Txt.setTextColor(ContextCompat.getColor(this@ZyzKaoQingMainActivity, R.color.page_sub))
                        tab01Line.setBackgroundResource(R.color.transparent)
                        tab02Txt.setTextColor(ContextCompat.getColor(this@ZyzKaoQingMainActivity, R.color.page_title))
                        tab02Line.setBackgroundResource(R.color.theme_color)
                    }
                }
            }
        })
    }

    private fun initListener() {
        tab01View.setOnClickListener(this)
        tab02View.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v) {
            tab01View -> {
                viewPager.setCurrentItem(0, true)
            }
            tab02View -> {
                viewPager.setCurrentItem(1, true)
            }
        }
    }
}